# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=inetsim
pkgver=1.3.2
pkgrel=5
groups=('blackarch' 'blackarch-defensive' 'blackarch-honeypot')
pkgdesc='A software suite for simulating common internet services in a lab environment, e.g. for analyzing the network behaviour of unknown malware samples.'
url='http://www.inetsim.org/'
arch=('any')
license=('GPL3')
depends=('perl' 'perl-net-server' 'perl-ipc-shareable' 'openssl' 'perl-net-dns')
source=("http://www.inetsim.org/downloads/$pkgname-$pkgver.tar.gz")
sha512sums=('2c26d4edbb3f77534d94976184d83bda4ba84b19534b39379d160d3f9b0fd4d437476885a1e20dd2d1d488e4a19910424db1f11587ea2d697ecfbbba77e76a05')
install="$pkgname.install"

package() {
  cd "$pkgname-$pkgver"

  install -dm 755 "$pkgdir/etc"
  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/var/lib"
  install -dm 755 "$pkgdir/usr/share/$pkgname"
  install -dm 755 "$pkgdir/usr/share/doc/$pkgname"
  install -dm 755 "$pkgdir/var/log/$pkgname"

  # Program.
  cp -R --no-preserve=ownership contrib lib inetsim "$pkgdir/usr/share/$pkgname"

  # Logs.
  ln -s /var/log/inetsim "$pkgdir/usr/share/$pkgname/report"
  ln -s /var/log/inetsim "$pkgdir/usr/share/$pkgname/log"

  # Data.
  cp -R --no-preserve=ownership data "$pkgdir/var/lib/$pkgname"
  ln -s /var/lib/inetsim "$pkgdir/usr/share/$pkgname/data"

  # Configuration.
  cp -R --no-preserve=ownership conf "$pkgdir/etc/$pkgname"
  ln -s /etc/inetsim "$pkgdir/usr/share/$pkgname/conf"

  # Man pages.
  cp -R --no-preserve=ownership man "$pkgdir/usr/share"

  # Documentation.
  install -m 644 CHANGES README doc/* "$pkgdir/usr/share/doc/$pkgname"

  # Permissions.
  # This is pretty much copypasted from the upstream-provided `setup.sh`.
  # Group ownership is set in the install file.
  chmod 770 "$pkgdir/var/log/$pkgname"
  chmod g+w "$pkgdir/var/lib/$pkgname/http/postdata"
  chmod g+w "$pkgdir/var/lib/$pkgname/ftp/upload"
  chmod g+w "$pkgdir/var/lib/$pkgname/tftp/upload"

  # TODO: install cleanup.sh?
  # Joint script.
  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec perl -T $pkgname "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

